package com.atguigu.algorithm;

import java.util.Arrays;

public class TheTwoNumAppOdd {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(findTheTwoNum(new int[]{0,0,1,2})));
        System.out.println(Arrays.toString(findTheTwoNum(new int[]{3,1,1,2,2,5})));
    }
    public static int[] findTheTwoNum(int[] nums){
        int eor1=0;
        for(int num:nums){
            eor1^=num;
        }
        //此时得到 a ^ b 的结果
        int rightOne=eor1&(~eor1+1);
        //得到最右边的1
        int eor2=0;
        for(int i=0;i<nums.length;i++){
            if((rightOne&nums[i])==0){
                eor2^=nums[i];
            }
        }
        int[] res=new int[2];
        res[1]=eor2;
        res[0]=eor1^eor2;
        return res;
    }
}
